﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace _13_webAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        [HttpPost]
        public LoginReponse Login(LoginRequest req)
        {
            if (req.UserName == "admin" && req.PassWord == "123456")
            {
                var items = Process.GetProcesses().Select(x => new RrocessInfo(x.Id, x.ProcessName, x.WorkingSet64)).ToArray();
                return new LoginReponse(true, items);
            }
            else {
                return new LoginReponse(false, null);
            }
        }
    }

    public record LoginRequest(string UserName,string PassWord);
    public record RrocessInfo(long Id,string Name,long WorkingSet);
    public record LoginReponse(bool OK, RrocessInfo[]? processInfos);
}
